package com.jxtc.enterprise.hr.controller;

import com.jxtc.enterprise.hr.dto.HrLoginFormDTO;
import com.jxtc.enterprise.common.utils.Result;
import com.jxtc.enterprise.common.utils.ResultGenerator;
import com.jxtc.enterprise.hr.service.HrLoginService;
import com.jxtc.enterprise.hr.vo.HrLoginSuccessVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/jxtc/enterprise/hr")
@RequiredArgsConstructor
public class HrLoginController {

    private final HrLoginService hrLoginService;

    @ApiResponse(responseCode = "200", description = "登录成功时，code 返回 200， data 返回公司相关公司")
    @ApiResponse(responseCode = "200", description = "登录失败时，code 返回 401, message 为错误提示信息，data 为空")
    @Operation(summary = "5.1 HR 登录接口", tags = {"5. HR 网页登录登出"}, operationId = "5.1")
    @PostMapping("/login")
    public Result<HrLoginSuccessVO> login(@Valid @RequestBody HrLoginFormDTO dto) {
        HrLoginSuccessVO vo = hrLoginService.login(dto);
        return ResultGenerator.genSuccessResult(vo);
    }

    @ApiResponse(responseCode = "200", description = "登出成功时，code 返回 200， data 为空")
    @ApiResponse(responseCode = "200", description = "登出失败时，code 返回 400, message 为错误提示信息")
    @Parameter(name = "companyId", description = "公司 ID", example = "c752804d0cd410267f404dd3f0457a57")
    @Operation(summary = "5.2 HR 登出接口", tags = {"5. HR 网页登录登出"}, operationId = "5.2")
    @GetMapping("/logout")
    public Result<Void> logout(@RequestParam String companyId) {
        return ResultGenerator.genSuccessResult();
    }
}
